package cn.genmer.test.security;

import cn.genmer.test.security.model.User;
import cn.genmer.test.security.utils.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.locationtech.jts.io.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StopWatch;

import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.StampedLock;
import java.util.stream.Stream;

//import org.springframework.boot.test.context.SpringBootTest;
//
@SpringBootTest
@RunWith(SpringRunner.class)
public class StringTest2 {

    Logger logger = LoggerFactory.getLogger(StringTest2.class);

    private static SecureRandom random;

    static {
        try {
            random = SecureRandom.getInstance("SHA1PRNG");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
    private static ThreadLocal<String> threadLocal1 =new ThreadLocal<String>();
    private static ThreadLocal<String> threadLocal2 =new ThreadLocal<String>();
    private static Integer index = 1;
    //10000并发数
    private static final int THREAD_NUM =100000;
    //CountDownLatch发令枪
    private CountDownLatch countDownLatch = new CountDownLatch(10);
    CyclicBarrier cyclicBarrier = new CyclicBarrier(10);


    public static void main(String[] args) {
//        Double distance =14.613701534307927D;
//            String distanceStr = null;
//            if (distance != null && distance > 0) distanceStr = String.format("%.2f", distance);
//        System.out.println(distanceStr);
        Integer num = null;
        boolean b = num == 0;
        System.out.println(b);
    }

    @Test
    public void testList() throws InterruptedException, java.text.ParseException, NoSuchAlgorithmException {
        List<Object> list = new ArrayList<>();
        list.add(null);

        System.out.println(list.isEmpty());
    }
    @Test
    public void testParameterPassing() throws InterruptedException, java.text.ParseException, NoSuchAlgorithmException {
        Integer[] a = new Integer[10];
        for (int i = 0; i < a.length; i++) {
            a[i] = 0;
        }

        Integer b = a[3];
        b=1;

        System.out.println(a[3]);
        System.out.println(b);
    }
    @Test
    public void testCalcDistance() throws InterruptedException, java.text.ParseException, NoSuchAlgorithmException {
        // map可以存null、“”为key
        Map<String, Integer> map = new HashMap<>();
        map.put(null, 1);
        map.put("", 1);
        System.out.println(map);
    }
    @Test
    public void testMap() throws InterruptedException, java.text.ParseException, NoSuchAlgorithmException {
        // map可以存null、“”为key
        Map<String, Integer> map = new HashMap<>();
        map.put(null, 1);
        map.put("", 1);
        System.out.println(map);
    }
    @Test
    public void testInteger() throws InterruptedException, java.text.ParseException, NoSuchAlgorithmException {
//        Integer.valueOf(null);
//        Integer.valueOf("");
//        Integer.valueOf("null");

        Integer signSiteNumThreshold = 10;
        Double signSiteDistRateThreshold = 0.8D;
        try {
            signSiteNumThreshold = 20;
            signSiteDistRateThreshold =  Double.valueOf("null");
        } catch (Exception e){
        }
        System.out.println(signSiteNumThreshold);
        System.out.println(signSiteDistRateThreshold);
    }
    @Test
    public void testExistForRach() throws InterruptedException, java.text.ParseException, NoSuchAlgorithmException {
        // forEach return是continue的作用
        ArrayList<Integer> integerList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            integerList.add(i);
        }
        integerList.stream().parallel().forEach(integer -> {
            if (integer == 5 ) return;
            System.out.println(integer);
        });
    }
    @Test
    public void testDoubel() throws InterruptedException, java.text.ParseException, NoSuchAlgorithmException {
        double maxAppearTimes = 0L;
        maxAppearTimes = 78;
//        BigDecimal bigDecimal = new BigDecimal(maxAppearTimes / 100L).setScale(2,BigDecimal.ROUND_HALF_UP);
//        System.out.println(bigDecimal.doubleValue());
        System.out.println(maxAppearTimes / 100);
    }
    @Test
    public void testTimeSubtraction() throws InterruptedException, java.text.ParseException, NoSuchAlgorithmException {
       String startTime = "2023-04-26 00:00:00";
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String endTime = null;
        LocalDateTime localDateTime = LocalDateTime.parse(startTime, df).plusHours(24);
        endTime = localDateTime.format(df);
        System.out.println(startTime + "-" + endTime);
    }
    @Test
    public void testTrunOff() throws InterruptedException, java.text.ParseException, NoSuchAlgorithmException {
        String jobName  = "反馈地址标准化任务001(跑完)";
        String taskName = "反馈地址标准化任务001";
        if (jobName.indexOf(taskName.toString()) != -1){
            System.out.println("相等");
        }
    }
    @Test
    public void testStopWatch() throws InterruptedException, java.text.ParseException, NoSuchAlgorithmException {
        StopWatch stopWatch = new StopWatch("程序入口: calcStandardAddressId(String address)");
        stopWatch.start("【第一段】获取结构化地址库");
        stopWatch.stop();
        System.out.println(stopWatch.prettyPrint());
    }
    @Test
    public void testLongCalc() throws InterruptedException, java.text.ParseException, NoSuchAlgorithmException {
        Integer structureAddressCount = 6;
        Integer structureAddressCountNear1000m = -1;
        Double aggregationAccuracy = new Double(structureAddressCountNear1000m) / new Double(structureAddressCount);
        if (aggregationAccuracy > 0 && aggregationAccuracy < 1 ){
            BigDecimal bigDecimal = new BigDecimal(aggregationAccuracy);
            aggregationAccuracy = bigDecimal.setScale(2, BigDecimal.ROUND_UP).doubleValue();
        }
        System.out.println(aggregationAccuracy);
    }
    @Test
    public void testRandom() throws InterruptedException, java.text.ParseException, NoSuchAlgorithmException {
        long marked = System.currentTimeMillis();
        // 创建 SecureRandom 对象，并设置加密算法
//        SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
//        long nano = Calendar.getInstance().getTime().getTime();
//        System.out.println(nano);
        for (int i = 0; i < 100; i++) {
            // 3位随机数
            System.out.println(generateStandardIdSimplify());
//            System.out.println(random.nextInt(900) + 100);
        }
        System.out.println("耗时: " + (System.currentTimeMillis() - marked));
    }
    /**
     * 生成标准化地址库ID - 28位 (6位随机数*2)12+(时间戳)13+(三位随机数)3
     * @return
     */
    private static String generateStandardIdSimplify(){
        StringBuilder builder = new StringBuilder();
        builder.append((int)(Math.random()*900000) + 100000)
                .append((int)(Math.random()*900000) + 100000)
                .append(Calendar.getInstance().getTime().getTime())
                .append((int)(Math.random()*900) + 100);
        return builder.toString();
    }
    @Test
    public void testTransformUTCStrToDate() throws InterruptedException, java.text.ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

        System.out.println(format.parse("2020-01-01T06:44:32.000Z"));
    }
    @Test
    public void testaddDate() throws InterruptedException, java.text.ParseException {
        String date = "2023-02-28";
        System.out.println(DateUtil.formatDate(addDate(date), "yyyy-MM-dd"));

    }
    @Test
    public void testHash(){
        int hash = 125;
        int n = 16;
        System.out.println( (n - 1) & hash);
        ReentrantLock reentrantLock = new ReentrantLock();
        ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
        StampedLock stampedLock = new StampedLock();

        List<Object> list = new ArrayList<>();
//        list.stream().parallel()
    }


    @Test
    public void testDeadLock() {
        ArrayList<Thread> threads = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            Thread thread = new Thread(new Runnable() {
                @SneakyThrows
                @Override
                public void run() {
                    synchronized (index) {
                        if (index / 2 == 1) {
                            Thread.sleep(1000);
                            System.out.println("gg2调用index为：" + index);
                        } else {
                            Thread.sleep(1000);
                            System.out.println("gg调用index为：" + index);
                        }
                        index++;
                        if (index >= 3) {
                            index = 1;
                        }
                    }
                }
            });
            threads.add(thread);
        }
        for (int i = 0; i < 1000; i++) {
            threads.get(i).start();
        }
    }

    /**
     * 格式化区域
     * @param coordinates
     * @return
     */
    protected String coordinatesFormat(String coordinates) {
        if (StringUtils.isBlank(coordinates)) return null;
        String p = JSONObject.parseObject(coordinates).getString("coordinates");
        return p.substring(1, p.length() - 1);
    }
    @Test
    public void findClassLoader() {
        System.out.println(ClassLoader.getSystemClassLoader());
        System.out.println(ClassLoader.getSystemClassLoader().getParent());
        System.out.println(ClassLoader.getSystemClassLoader().getParent().getParent());
    }
    @Test
    public void jsonobjectTest() {
        JSONObject json = new JSONObject();
        json.put("addressFixTime", "202207051011");
        json.put("aa", "111");
        json.put("addressFixTime", "111");
        System.out.println(json);
    }
    @Test
    public void timeToStringContrast() {
        LocalDateTime start = LocalDateTime.now().minusMinutes((long) 2.5);
            LocalDateTime end = start.plusMinutes( 5);
        System.out.println(start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        System.out.println(start);
        System.out.println(end.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    }
    @Test
    public void testPolygon() throws ParseException {
//        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
//        WKTReader reader = new WKTReader(geometryFactory);
//        String wktPolygon1 = "POLYGON((115.056659208438 22.8705758182769, 115.056659208438 22.8630881201852, 115.075378453668 22.8630881201852, 115.073267702012 22.8676901910949, 115.064758191781 22.8712427237672, 115.060642026572 22.8712427237672, 115.056659208438 22.8705758182769))";
//        Geometry geometry1 = reader.read(wktPolygon1);
//        // 图形存在自相交的情况
//        String wktPolygon2 = "MULTIPOLYGON (((115.081751296 22.877495404, 115.08235485099999 22.877178259000004, 115.08187908699995 22.877199625000003, 115.08186948800005 22.877064256999972, 115.08234682600005 22.877049725000006, 115.08235485099999 22.877178259000004, 115.08253756700003 22.87708225, 115.081394789 22.876617703000022, 115.081393606 22.876618759999985, 115.08134342999995 22.876644435999992, 115.08130771200001 22.876678020999975, 115.08127786700004 22.87672623200001, 115.08107261099997 22.87712563399998, 115.08103419400004 22.877173486000004, 115.08102423900004 22.877191219999986, 115.08102438699996 22.877209929999992, 115.08103463199996 22.87722856900001, 115.08104820799997 22.87724302999999, 115.08118117100003 22.877315925000005, 115.08137075299999 22.87741251800003, 115.081543839 22.877451877999988, 115.08165843200004 22.877471886000023, 115.08169104499996 22.877482059999977, 115.081751296 22.877495404)))";
//        Geometry geometry2 = reader.read(wktPolygon2);
//        // 自相交
//        Geometry geometry2IntersectGeometry2 = geometry2.intersection(geometry2);
//        Geometry geometry1IntersectGeometry2 = geometry1.intersection(geometry2IntersectGeometry2);
//        System.out.println(geometry1IntersectGeometry2);
    }

    @Test
    public void testhashSet() throws ParseException {
//        List<NewSiteImportExcelVO> siteInfoList = new ArrayList<>();
//        siteInfoList.add(new NewSiteImportExcelVO("中通智运", "512003", "410203005000", "street"));
//        siteInfoList.add(new NewSiteImportExcelVO("中通智运", "512003", "410203005000", "street"));
//        siteInfoList.add(new NewSiteImportExcelVO("中通智运", "512002", "410203005000", "street"));
//        HashSet<Object> set = new HashSet<>();
//        for (int i = 0; i < siteInfoList.size(); i++) {
//            if (!set.add(siteInfoList.get(i)))
//                System.out.println(String.format("当前文档第%s行数据为重复存在数据！", i));
//        }
//        System.out.println();

        ArrayList<User> list = new ArrayList<>();
        list.add(new User("贺学武", "男"));
        list.add(new User("贺学武", "男"));
        list.add(new User("宁 浩", "男"));
        HashSet<Object> set = new HashSet<>();
        for (int i = 0; i < list.size(); i++) {
            if (!set.add(list.get(i)))
                System.out.println(String.format("当前文档第%s行数据为重复存在数据！", i));
        }
        // 结论 lombok为我们重写了hashCode和equals方法，这使得两个实例化的对象进行比较时，按照lombok为我们规定的规则进行比较。
        System.out.println();

    }

    @Test
    public void subListTest() throws InterruptedException {
        // subList不取toIndex(边界)
//        ArrayList<Integer> integers = new ArrayList<>();
//        integers.add(1);
//        integers.add(2);
//        integers.add(3);
//        integers.add(4);
//        integers.add(5);
//        integers.add(6);
//        List<Integer> integers1 = integers.subList(0, 3);
//        List<Integer> integers2 = integers.subList(3, 6);


//        System.out.println(Math.round(201%50));
        int reMatchListSize = 20;
//        int cycleNum = reMatchListSize%50 == 0 ? Math.round(reMatchListSize/50) : Math.round(reMatchListSize/50) + 1;
//        System.out.println(cycleNum);
//        int showIndex = i * 50 + 50 > reMatchListSize ? reMatchListSize - i * 50 : i * 50 + 50;
//        System.out.println(showIndex);

        // 开启8线程版本
        // 单线程处理数量
        int singleThreadProcessNum = 25;
        // 需要开启的线程数
        int cycleNum = reMatchListSize%singleThreadProcessNum == 0 ? Math.round(reMatchListSize/singleThreadProcessNum) : Math.round(reMatchListSize/singleThreadProcessNum) + 1;
        int i = cycleNum - 1;
        System.out.println(cycleNum);
        int showIndex = i * singleThreadProcessNum + singleThreadProcessNum > reMatchListSize ? reMatchListSize - i * singleThreadProcessNum : i * singleThreadProcessNum + singleThreadProcessNum;
        System.out.println(showIndex);
    }

    @Test
    public void getMethodStackTest() throws InterruptedException {
        conCourrentTest2();
        Throwable throwable = new Throwable();
        StackTraceElement[] stackTrace = throwable.getStackTrace();
    }

    @Test
    public void getMethodStack() throws InterruptedException {
        Throwable throwable = new Throwable();
        StackTraceElement[] stackTrace = throwable.getStackTrace();
        System.out.println(stackTrace[0]);
        System.out.println(stackTrace[1]);
        System.out.println(stackTrace[2]);

    }

    @Test
    public void conCourrentTest2() throws InterruptedException {
        ConcurrentHashMap<Object, Object> map = new ConcurrentHashMap<>();
        map.get("");
        System.out.println(UUIDUtils.getUUID());
        getMethodStack();
    }

    /**
     * 并发测试 网点A莫名出现问题
     * @throws InterruptedException
     */
    @Test
    public void conCourrentTest() throws InterruptedException {
        Thread.sleep(100);
        Update update = Update.update("site_a_name", "网点aa");
        update.push("site_b_name", "网点B" + Math.random());
        update.push("distance", "4458"+ Math.random());
        System.out.println(update);
        Thread.sleep(100);

    }

    @Test
    public void testInterface()throws ExecutionException,InterruptedException {
        for(int i=0;i< THREAD_NUM;i++){//运行10000次,10000个线程
//            final String orderCode =String.valueOf(100+i);
            Thread thread =new Thread(()->{//1.8方式， thread 的run 方法
                try {
                    countDownLatch.countDown();//计数减1
                    countDownLatch.await();//等待
                    conCourrentTest2();
                    // System.out.println("查询结果："+result);
                }catch (Exception e){
                    e.printStackTrace();
                }
            });
            thread.start();
        }
        //最后一个循环结束、计数变为0，
//
//        Thread.sleep(5000);

    }

    /**
     * 两条线段是否相交
     */
    @Test
    public void lineIntersection(){
        trans();
    }
    private void trans(){
//  [
//        117.46005,
//                39.138564
//                    ],
//                    [
//        117.459578,
//                39.133105
//                    ],
//                    [
//        117.466573,
//                39.132523
//                    ]
//
        intersection(117.46005,39.138564,117.459578,39.133105,117.466573,39.132523,117.46005, 39.138564);
    }
    /**两【线段】是否相交
     * @param l1x1 线段1的x1
     * @param l1y1 线段1的y1
     * @param l1x2 线段1的x2
     * @param l1y2 线段1的y2
     * @param l2x1 线段2的x1
     * @param l2y1 线段2的y1
     * @param l2x2 线段2的x2
     * @param l2y2 线段2的y2
     * @return 是否相交
     */
    public static boolean intersection(double l1x1, double l1y1, double l1x2, double l1y2,
                                       double l2x1, double l2y1, double l2x2, double l2y2)
    {
        // 快速排斥实验 首先判断两条线段在 x 以及 y 坐标的投影是否有重合。 有一个为真，则代表两线段必不可交。
        if (Math.max(l1x1,l1x2) < Math.min(l2x1 ,l2x2)
                || Math.max(l1y1,l1y2) < Math.min(l2y1,l2y2)
                || Math.max(l2x1,l2x2) < Math.min(l1x1,l1x2)
                || Math.max(l2y1,l2y2) < Math.min(l1y1,l1y2))
        {
            return false;
        }
        // 跨立实验  如果相交则矢量叉积异号或为零，大于零则不相交
        if ((((l1x1 - l2x1) * (l2y2 - l2y1) - (l1y1 - l2y1) * (l2x2 - l2x1))
                * ((l1x2 - l2x1) * (l2y2 - l2y1) - (l1y2 - l2y1) * (l2x2 - l2x1))) > 0
                || (((l2x1 - l1x1) * (l1y2 - l1y1) - (l2y1 - l1y1) * (l1x2 - l1x1))
                * ((l2x2 - l1x1) * (l1y2 - l1y1) - (l2y2 - l1y1) * (l1x2 - l1x1))) > 0)
        {
            return false;
        }
        return true;
    }

    /**
     * 两条线段是否相交
     * 验证 (a*b)是value a*b是variable
     */
    @Test
    public void expressionVerify(){
        int a = 1;
        int b = 2;
        System.out.println(a*b++);
    }
    @Test
    public void bitwiseTest(){
        int length = 49;
        int seventh = (length >> 3) + (length >> 6) + 1;
        System.out.println(seventh);
    }
    @Test
    public void arrayCopyTest(){
       int[] arr = {1,0,0};

        System.out.println(Arrays.toString(arr));
        methodTest(arr);
        System.out.println(Arrays.toString(arr));

    }
    @Test
    public void test_parallel() throws Exception{

        long start = System.nanoTime();

        Long sum = Stream
                .iterate(0L, (x) -> x + 1)
                .limit(100_000_000l)
                .parallel()
                .reduce(0L, Long::sum);

        Long end = System.nanoTime();

        System.out.println("cost:" + (end -start)/1_000_000);

    }

    private void methodTest(int[] arr){
        int[] arr2 = {0,0,1};
        arr = arr2;
    }
    @Test
    public void testCoordinateConversion(){
        String bg = "119.131999,26.150000";
        String bgbd = "119.138482,26.156035";
        String bgbdTrans = transZBGLocation(bgbd);
        String bgbdTrans2 = transBGBDLocation3(bgbd);

        System.out.println(String.format("bg: %s", bg));
        System.out.println(String.format("bgbd: %s", bgbd));
        System.out.println(String.format("bgbdTrans: %s", bgbdTrans));
        System.out.println(String.format("bgbdTrans2: %s", bgbdTrans2));
    }

    @Test
    public void testThreadJoin() throws InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10,10,0,TimeUnit.MINUTES, new LinkedBlockingDeque<>(10), new ThreadPoolExecutor.DiscardPolicy());

        List<Thread> threads = new ArrayList<>();
        Runnable runnable = () -> {
            try {
                System.out.println(Thread.currentThread().getName() + "开始执行...");
                Thread.sleep(5000);
                System.out.println(Thread.currentThread().getName() + "执行结束!");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        };
        long start = System.currentTimeMillis();
        for (int i = 0; i < 500; i++) {
            Thread thread = new Thread(runnable);
            threads.add(thread);
            thread.start();
        }


        for (int i = 0; i < threads.size(); i++) {
            threads.get(i).join();
        }
        System.out.println(System.currentTimeMillis() - start + "ms");
    }

    @Test
    public void testListAllocation() throws BrokenBarrierException, InterruptedException {
//        System.out.println("cyclicBarrier getNumberWaiting: " + cyclicBarrier.getNumberWaiting());
//        cyclicBarrier.reset();
        CountDownLatch countDownLatch1 = new CountDownLatch(10);
        int executeNum = 100;
        int THREAD_CORE_NUM = 10;
        int singleTimeNum = executeNum / THREAD_CORE_NUM;
        for (int i = 0; i < THREAD_CORE_NUM; i++) {
            int finalI = i;
            new Thread(() -> {
                try {
                    System.out.println((finalI *singleTimeNum) + ":" + (finalI *singleTimeNum+singleTimeNum));
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("【调用GIS入库接口任务】{}线程执行异常，具体信息：{}");
                } finally {
                    countDownLatch1.countDown();
                }

            }).start();
        }
//        cyclicBarrier.await();
        countDownLatch1.await();
        System.out.println();
        System.out.println("同时结束");
        System.out.println("cyclicBarrier getNumberWaiting: " + cyclicBarrier.getNumberWaiting());
    }


    @Test
    public void testSystemUsage() {
        final long GB = 1024 * 1024 * 1024;
        while (true) {
            OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
            String osJson = JSON.toJSONString(operatingSystemMXBean);
//            System.out.println("osJson is " + osJson);
            JSONObject jsonObject = JSON.parseObject(osJson);
            double processCpuLoad = jsonObject.getDouble("processCpuLoad") * 100;
            double systemCpuLoad = jsonObject.getDouble("systemCpuLoad") * 100;
            Long totalPhysicalMemorySize = jsonObject.getLong("totalPhysicalMemorySize");
            Long freePhysicalMemorySize = jsonObject.getLong("freePhysicalMemorySize");
            double totalMemory = 1.0 * totalPhysicalMemorySize / GB;
            double freeMemory = 1.0 * freePhysicalMemorySize / GB;
            double memoryUseRatio = 1.0 * (totalPhysicalMemorySize - freePhysicalMemorySize) / totalPhysicalMemorySize * 100;

            StringBuilder result = new StringBuilder();
            result.append("系统CPU占用率: ")
                    .append(twoDecimal(systemCpuLoad))
                    .append("%，内存占用率：")
                    .append(twoDecimal(memoryUseRatio))
                    .append("%，系统总内存：")
                    .append(twoDecimal(totalMemory))
                    .append("GB，系统剩余内存：")
                    .append(twoDecimal(freeMemory))
                    .append("GB，该进程占用CPU：")
                    .append(twoDecimal(processCpuLoad))
                    .append("%");
            System.out.println(result.toString());

            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public double twoDecimal(double doubleValue) {
        BigDecimal bigDecimal = new BigDecimal(doubleValue).setScale(2, RoundingMode.HALF_UP);
        return bigDecimal.doubleValue();
    }


    private String transZBGLocation(String zbgLocation){
        String[] split = zbgLocation.split(",");
        double[] gps = CoordinateTransformUtil.bd09togcj02(Double.valueOf(split[0]), Double.valueOf(split[1]));
        return new StringBuilder().append(gps[0]).append(",").append(gps[1]).toString();
    }
    private String transBGBDLocation(String bgbdLocation){
        String[] split = bgbdLocation.split(",");
        GPSConverterUtils.GPS gps = GPSConverterUtils.bd09_To_Gcj02(Double.valueOf(split[0]), Double.valueOf(split[1]));
        return new StringBuilder().append(gps.getLon()).append(",").append(gps.getLat()).toString();
    }
    private String transBGBDLocation3(String bgbdLocation){
        String[] split = bgbdLocation.split(",");
        GeoUtil.Point point = GeoUtil.convertBaidu2Mars(Double.valueOf(split[1]), Double.valueOf(split[0]));
        return new StringBuilder().append(point.getLon()).append(",").append(point.getLat()).toString();
    }

    /**
     *毫秒转换分秒
     *@parammillis
     *@return
     */
    public static String timeUnitTransfer(long millis){
        if (millis < 1000){
            return String.format("%sms", millis);
        } else if (millis < 10000){
            return String.format("%ss %sms", TimeUnit.MILLISECONDS.toSeconds(millis), millis%1000);
        }else {

        }
        return String.format("%smin %ss", TimeUnit.MILLISECONDS.toMinutes(millis), (millis / 1000) % 60);
    }

    private Date addDate(String time){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DateUtil.formatD(time, "yyyy-MM-dd"));
        // 把日期往后增加一天,整数  往后推,负数往前移动
        calendar.add(Calendar.DATE, 1);
        return calendar.getTime();
    }

}

